//
// Created by Jisam on 21/09/2024 7:45 PM.
// Solution of  求最大和
#include <bits/stdc++.h>

using namespace std;
int n, m;

const int maxn = 1005;
int a[maxn][maxn]={0};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            a[i][j] += max( a[i - 1][j],a[i ][j- 1]);
            ans = max(ans,a[i][j]);
        }
    }

    cout << ans ;
    return 0;
}